const _ = require('lodash');
const userInfoFacade = require('../../app/facade/userInfo.server.facade.js');

module.exports = {
    getUserInfoByUserId:getUserInfoByUserId,
    adduserInfo:adduserInfo
}

function getUserInfoByUserId(req,res,next){
    let params = req.params;
    let userId = params.userId;
    if(_.isEmpty(userId)){
        return next(new Error('user id is empty'));
    }else{
        userInfoFacade.getUserInfoByUserId(userId,(error,result)=>{
            if(error){
                return next(new Error(error));
            }else{
                return res.json(result);
            }
        });
    }
}

function adduserInfo(req,res,next){
    let body = req.body;
    let userInfo = body;
    if(_.isEmpty(userInfo)){
        return next(new Error('user info is empty'));
    }else{
        userInfoFacade.adduserInfo(userInfo,(error,result)=>{
            if(error){
                return next(new Error(error));
            }else{
                return res.json(result);
            }
        });
    }
}